var Dialg = (function(){
	return {
		del : function(callback, content, title){
			if(!content){
				content = "确定删除吗？";
			}
			if(!title){
				title = "删除";
			}
			
			var d = $('#deleteDialg');
			d.find('[sign=content]').html(content);
			d.find('[sign=title]').html(title);
			d.find('[sign="ok"]').one('click', function(){
				if(callback){
					callback();
				}
				d.modal('hide');
			});
			d.modal({
				backdrop:true,
				keyboard:true,
				show:true
			});
		}, 
		edit : function(callback, json){
			var d = $('#editDialg');
			//标题
			if(json){
				d.find('[who="title"]').html('修改');
			}else{
				d.find('[who="title"]').html('增加');
				json = {status:1};
			}
			
			//值
			d.find('[sign]').each(function(){
				var $this = $(this);
				var value = json[$this.attr('sign')];
				if(value){
					$this.val(value);
				}else{
					$this.val('');
				}
			});
			var status = d.find('[sign="status"]').html('禁用');
			if(json.status == 0){
				status.html('启用');
			}
			status.trigger('click');
			
			(function(){
				var ok = d.find('[who="ok"]');
				var e = function(){
					var result = true;
					if(callback){
						var data = {};
						d.find('[sign]').each(function(){
							var $this = $(this);
							data[$this.attr('sign')] = $this.val();
						});
						data.status = 0;
						if(d.find('[sign="status"]').html() == '启用'){
							data.status = 1;
						}
						/*
						data.path = d.find('[sign="path"]').val();
						data.v = d.find('[sign="v"]').val();
						data.sql = d.find('[sign="sql"]').val();
						data.js = d.find('[sign="js"]').val();
						*/
						result = callback(data, json);
					}
					if(result !== false){
						ok.unbind();
						d.modal('hide');
					};
				};
				ok.click(e);
			})();
			d.modal({
				backdrop:true,
				keyboard:true,
				show:true
			});
		}
	};
})();

$(function(){
	$('.page-header').live('hover', function(e){
		if(e.type=='mouseover' || e.type=='mouseenter'){
			$(this).find('h1 .tools').show();
		}else{
			$(this).find('h1 .tools').hide();
		}
	});
	
	$('.page-header table tr').live('hover', function(e){
		if(e.type=='mouseover' || e.type=='mouseenter'){
			$(this).find('.tools').show();
		}else{
			$(this).find('.tools').hide();
		}
	});
	$('.modal-body [sign="status"]').click(function(){
		var $this = $(this);
		if($this.html() == '启用'){
			$this.html('禁用').attr('class', 'badge badge-warning');
		}else{
			$this.html('启用').attr('class', 'badge badge-success');
		}
	});
});